﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using GaoTang.Configuration;
using GaoTang.Web;

namespace GaoTang.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class GaoTangDbContextFactory : IDesignTimeDbContextFactory<GaoTangDbContext>
    {
        public GaoTangDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<GaoTangDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            GaoTangDbContextConfigurer.Configure(builder, configuration.GetConnectionString(GaoTangConsts.ConnectionStringName));

            return new GaoTangDbContext(builder.Options);
        }
    }
}
